package com.campus.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.campus.entity.System.SysMenu;
import com.campus.mapper.SysMenuMapper;
import com.campus.service.SysMenuService;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * @author java1234
 * @description 针对表【sys_menu】的数据库操作Service实现
 * @createDate 2022-09-15 07:52:51
 */
@Service
public class SysMenuServiceImpl extends ServiceImpl<SysMenuMapper, SysMenu> implements SysMenuService {

    @Override
    public List<SysMenu> buildTreeMenu(List<SysMenu> sysMenuList) {
        ArrayList<SysMenu> resultMenuList = new ArrayList<>();
        for (SysMenu sysMenu : sysMenuList) {
            for (SysMenu menu : sysMenuList) {
                if (menu.getParentId().equals(sysMenu.getId())) {
                    sysMenu.getChildren().add(menu);
                }
            }

            if (sysMenu.getParentId().equals(0L)) {
                resultMenuList.add(sysMenu);
            }
        }
        return resultMenuList;
    }
}




